<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<title>BOOST_TEST: universal and general purpose assertions</title>
<link rel="stylesheet" href="../../boostbook.css" type="text/css">
<meta name="generator" content="DocBook XSL Stylesheets V1.79.1">
<link rel="home" href="../../index.html" title="Boost.Test">
<link rel="up" href="../testing_tools.html" title="Writing unit tests">
<link rel="prev" href="tools_assertion_severity_level.html" title="Assertion severity level">
<link rel="next" href="reports.html" title="Reported information">
</head>
<body bgcolor="white" text="black" link="#0000FF" vlink="#840084" alink="#0000FF">
<table cellpadding="2" width="100%"><tr>
<td valign="top"><img alt="Boost C++ Libraries" width="277" height="86" src="../../../../../../boost.png"></td>
<td align="center"><a href="../../../../../../index.html">Home</a></td>
<td align="center"><a href="../../../../../../libs/libraries.htm">Libraries</a></td>
<td align="center"><a href="http://www.boost.org/users/people.html">People</a></td>
<td align="center"><a href="http://www.boost.org/users/faq.html">FAQ</a></td>
<td align="center"><a href="../../../../../../more/index.htm">More</a></td>
</tr></table>
<hr>
<div class="spirit-nav">
<a accesskey="p" href="tools_assertion_severity_level.html"><img src="../../../../../../doc/src/images/prev.png" alt="Prev"></a><a accesskey="u" href="../testing_tools.html"><img src="../../../../../../doc/src/images/up.png" alt="Up"></a><a accesskey="h" href="../../index.html"><img src="../../../../../../doc/src/images/home.png" alt="Home"></a><a accesskey="n" href="reports.html"><img src="../../../../../../doc/src/images/next.png" alt="Next"></a>
</div>
<div class="section">
<div class="titlepage"><div><div><h3 class="title">
<a name="boost_test.testing_tools.boost_test_universal_macro"></a><a class="link" href="boost_test_universal_macro.html" title="BOOST_TEST: universal and general purpose assertions">BOOST_TEST:
      universal and general purpose assertions</a>
</h3></div></div></div>
<p>
        The <span class="emphasis"><em>Unit Test Framework</em></span> provides an almost unique interface
        to a great range of test-case scenarios, through the <a class="link" href="../utf_reference/testing_tool_ref/assertion_boost_test_universal_macro.html" title="BOOST_TEST"><code class="computeroutput"><span class="identifier">BOOST_TEST</span></code></a> macro. The general form
        of <code class="computeroutput"><span class="identifier">BOOST_TEST</span></code> is the following:
      </p>
<pre class="programlisting"><span class="identifier">BOOST_TEST</span><span class="special">(</span><span class="identifier">statement</span><span class="special">);</span>
<span class="identifier">BOOST_TEST_</span><span class="special">&lt;</span><span class="identifier">level</span><span class="special">&gt;(</span><span class="identifier">statement</span><span class="special">,</span> <span class="identifier">optional_modifiers</span><span class="special">)</span>
</pre>
<p>
        An example of use might be the following:
      </p>
<h6>
<a name="boost_test.testing_tools.boost_test_universal_macro.h0"></a>
        <span class="phrase"><a name="boost_test.testing_tools.boost_test_universal_macro.example_descr"></a></span><a class="link" href="boost_test_universal_macro.html#boost_test.testing_tools.boost_test_universal_macro.example_descr">Example:
        BOOST_TEST overview</a>
      </h6>
<div class="informaltable"><table class="table">
<colgroup><col></colgroup>
<thead><tr><th>
                <p>
                  Code
                </p>
              </th></tr></thead>
<tbody><tr><td>
<pre xmlns:rev="http://www.cs.rpi.edu/~gregod/boost/tools/doc/revision" class="table-programlisting"><span class="preprocessor">#define</span> <span class="identifier">BOOST_TEST_MODULE</span> <span class="identifier">boost_test_macro_overview</span>
<span class="preprocessor">#include</span> <span class="special">&lt;</span><span class="identifier">boost</span><span class="special">/</span><span class="identifier">test</span><span class="special">/</span><span class="identifier">included</span><span class="special">/</span><span class="identifier">unit_test</span><span class="special">.</span><span class="identifier">hpp</span><span class="special">&gt;</span>

<span class="identifier">BOOST_AUTO_TEST_CASE</span><span class="special">(</span> <span class="identifier">test_macro_overview</span> <span class="special">)</span>
<span class="special">{</span>
  <span class="keyword">namespace</span> <span class="identifier">tt</span> <span class="special">=</span> <span class="identifier">boost</span><span class="special">::</span><span class="identifier">test_tools</span><span class="special">;</span>
  <span class="keyword">int</span> <span class="identifier">a</span> <span class="special">=</span> <span class="number">1</span><span class="special">;</span>
  <span class="keyword">int</span> <span class="identifier">b</span> <span class="special">=</span> <span class="number">2</span><span class="special">;</span>
  <span class="identifier">BOOST_TEST</span><span class="special">(</span><span class="identifier">a</span> <span class="special">!=</span> <span class="identifier">b</span> <span class="special">-</span> <span class="number">1</span><span class="special">);</span>
  <span class="identifier">BOOST_TEST</span><span class="special">(</span><span class="identifier">a</span> <span class="special">+</span> <span class="number">1</span> <span class="special">&lt;</span> <span class="identifier">b</span><span class="special">);</span>
  <span class="identifier">BOOST_TEST</span><span class="special">(</span><span class="identifier">b</span> <span class="special">-</span><span class="number">1</span> <span class="special">&gt;</span> <span class="identifier">a</span><span class="special">,</span> <span class="identifier">a</span> <span class="special">&lt;&lt;</span> <span class="string">" &lt; "</span> <span class="special">&lt;&lt;</span> <span class="identifier">b</span> <span class="special">-</span> <span class="number">1</span> <span class="special">&lt;&lt;</span> <span class="string">" does not hold"</span><span class="special">);</span>
  <span class="identifier">BOOST_TEST</span><span class="special">(</span><span class="identifier">a</span> <span class="special">==</span> <span class="identifier">b</span><span class="special">,</span> <span class="identifier">tt</span><span class="special">::</span><span class="identifier">bitwise</span><span class="special">());</span>
  <span class="identifier">BOOST_TEST</span><span class="special">(</span><span class="identifier">a</span> <span class="special">+</span> <span class="number">0.1</span> <span class="special">==</span> <span class="identifier">b</span> <span class="special">-</span> <span class="number">0.8</span><span class="special">,</span> <span class="identifier">tt</span><span class="special">::</span><span class="identifier">tolerance</span><span class="special">(</span><span class="number">0.01</span><span class="special">));</span>
<span class="special">}</span>
</pre>
              </td></tr></tbody>
</table></div>
<div class="informaltable"><table class="table">
<colgroup><col></colgroup>
<thead><tr><th>
                <p>
                  Output
                </p>
              </th></tr></thead>
<tbody><tr><td>
<pre xmlns:rev="http://www.cs.rpi.edu/~gregod/boost/tools/doc/revision" class="table-programlisting"><span class="special">&gt;</span> <span class="special">./</span><span class="identifier">boost_test_macro_overview</span> <span class="special">--</span><span class="identifier">log_level</span><span class="special">=</span><span class="identifier">all</span>
<span class="identifier">Running</span> <span class="number">1</span> <span class="identifier">test</span> <span class="keyword">case</span><span class="special">...</span>
<span class="identifier">Entering</span> <span class="identifier">test</span> <span class="identifier">module</span> <span class="string">"boost_test_macro_overview"</span>
<span class="identifier">test</span><span class="special">.</span><span class="identifier">cpp</span><span class="special">:</span><span class="number">12</span><span class="special">:</span> <span class="identifier">Entering</span> <span class="identifier">test</span> <span class="keyword">case</span> <span class="string">"test_macro_overview"</span>
<span class="identifier">test</span><span class="special">.</span><span class="identifier">cpp</span><span class="special">:</span><span class="number">17</span><span class="special">:</span> <span class="identifier">error</span><span class="special">:</span> <span class="identifier">in</span> <span class="string">"test_macro_overview"</span><span class="special">:</span> <span class="identifier">check</span> <span class="identifier">a</span> <span class="special">!=</span> <span class="identifier">b</span> <span class="special">-</span> <span class="number">1</span> <span class="identifier">has</span> <span class="identifier">failed</span> <span class="special">[</span><span class="number">1</span> <span class="special">==</span> <span class="number">1</span><span class="special">]</span>
<span class="identifier">test</span><span class="special">.</span><span class="identifier">cpp</span><span class="special">:</span><span class="number">18</span><span class="special">:</span> <span class="identifier">error</span><span class="special">:</span> <span class="identifier">in</span> <span class="string">"test_macro_overview"</span><span class="special">:</span> <span class="identifier">check</span> <span class="identifier">a</span> <span class="special">+</span> <span class="number">1</span> <span class="special">&lt;</span> <span class="identifier">b</span> <span class="identifier">has</span> <span class="identifier">failed</span> <span class="special">[</span><span class="number">1</span> <span class="special">+</span> <span class="number">1</span> <span class="special">&gt;=</span> <span class="number">2</span><span class="special">]</span>
<span class="identifier">test</span><span class="special">.</span><span class="identifier">cpp</span><span class="special">:</span><span class="number">19</span><span class="special">:</span> <span class="identifier">error</span><span class="special">:</span> <span class="identifier">in</span> <span class="string">"test_macro_overview"</span><span class="special">:</span> <span class="number">1</span> <span class="special">&lt;</span> <span class="number">1</span> <span class="identifier">does</span> <span class="keyword">not</span> <span class="identifier">hold</span>
<span class="identifier">test</span><span class="special">.</span><span class="identifier">cpp</span><span class="special">:</span><span class="number">20</span><span class="special">:</span> <span class="identifier">error</span><span class="special">:</span> <span class="identifier">in</span> <span class="string">"test_macro_overview"</span><span class="special">:</span> <span class="identifier">check</span> <span class="identifier">a</span> <span class="special">==</span> <span class="identifier">b</span> <span class="identifier">has</span> <span class="identifier">failed</span> <span class="special">[</span><span class="number">1</span> <span class="special">!=</span> <span class="number">2</span><span class="special">].</span> <span class="identifier">Bitwise</span> <span class="identifier">comparison</span> <span class="identifier">failed</span>
<span class="identifier">Mismatch</span> <span class="identifier">at</span> <span class="identifier">position</span> <span class="number">0</span>
<span class="identifier">Mismatch</span> <span class="identifier">at</span> <span class="identifier">position</span> <span class="number">1</span>
<span class="identifier">test</span><span class="special">.</span><span class="identifier">cpp</span><span class="special">:</span><span class="number">21</span><span class="special">:</span> <span class="identifier">error</span><span class="special">:</span> <span class="identifier">in</span> <span class="string">"test_macro_overview"</span><span class="special">:</span> <span class="identifier">check</span> <span class="identifier">a</span> <span class="special">+</span> <span class="number">0.1</span> <span class="special">==</span> <span class="identifier">b</span> <span class="special">-</span> <span class="number">0.8</span> <span class="identifier">has</span> <span class="identifier">failed</span> <span class="special">[</span><span class="number">1</span> <span class="special">+</span> <span class="number">0.10000000000000001</span> <span class="special">!=</span> <span class="number">1.2</span><span class="special">].</span> <span class="identifier">Relative</span> <span class="identifier">difference</span> <span class="identifier">exceeds</span> <span class="identifier">tolerance</span> <span class="special">[</span><span class="number">0.0909091</span> <span class="special">&gt;</span> <span class="number">0.01</span><span class="special">]</span>
<span class="identifier">test</span><span class="special">.</span><span class="identifier">cpp</span><span class="special">:</span><span class="number">12</span><span class="special">:</span> <span class="identifier">Leaving</span> <span class="identifier">test</span> <span class="keyword">case</span> <span class="string">"test_macro_overview"</span><span class="special">;</span> <span class="identifier">testing</span> <span class="identifier">time</span><span class="special">:</span> <span class="number">380u</span><span class="identifier">s</span>
<span class="identifier">Leaving</span> <span class="identifier">test</span> <span class="identifier">module</span> <span class="string">"boost_test_macro_overview"</span><span class="special">;</span> <span class="identifier">testing</span> <span class="identifier">time</span><span class="special">:</span> <span class="number">459u</span><span class="identifier">s</span>

<span class="special">***</span> <span class="number">5</span> <span class="identifier">failures</span> <span class="identifier">are</span> <span class="identifier">detected</span> <span class="identifier">in</span> <span class="identifier">the</span> <span class="identifier">test</span> <span class="identifier">module</span> <span class="string">"boost_test_macro_overview"</span>
</pre>
              </td></tr></tbody>
</table></div>
<p>
        The major features of this tool are:
      </p>
<div class="itemizedlist"><ul class="itemizedlist" style="list-style-type: disc; ">
<li class="listitem">
            a great flexibility for <code class="computeroutput"><span class="identifier">statement</span></code>
            which may be almost anything: full expression composed by several operations
            are supported and handled,
          </li>
<li class="listitem">
            an extended reporting capability in case of failure: not only <code class="computeroutput"><span class="identifier">BOOST_TEST</span></code> reports the location of
            the failure and a copy of <code class="computeroutput"><span class="identifier">statement</span></code>
            itself, but also the values of the operands that permits a rapid identification
            of the issues related to the failed assertion,
          </li>
<li class="listitem">
            the possibility to control better the behavior or the reports of the
            checks, in particular:
            <div class="itemizedlist"><ul class="itemizedlist" style="list-style-type: circle; ">
<li class="listitem">
                  floating point comparison: the tolerance may be provided, either
                  using the <code class="computeroutput"><span class="identifier">BOOST_TEST</span></code>
                  directly with <code class="computeroutput"><span class="identifier">optional_modifiers</span></code>,
                  or with <span class="emphasis"><em>decorators</em></span> (see <a class="link" href="extended_comparison/floating_point.html" title="Floating point comparison">here</a>
                  for more details),
                </li>
<li class="listitem">
                  container/collection comparisons: different operations for comparison
                  are provided out of the box for comparing collection of elements
                  (default, per-element, lexicographic), with extended diagnostic
                  on failures (covered in <a class="link" href="extended_comparison/collections.html" title="Collections comparison">this</a>
                  section),
                </li>
<li class="listitem">
                  string comparison: C-strings operands are automatically detected
                  and the comparisons are performed as if <code class="computeroutput"><span class="identifier">std</span><span class="special">::</span><span class="identifier">string</span></code>
                  objects were used,
                </li>
<li class="listitem">
                  optional failure message,
                </li>
<li class="listitem">
                  bitwise comparison, providing extended diagnostic in case of failure
                </li>
</ul></div>
          </li>
</ul></div>
<div class="warning"><table border="0" summary="Warning">
<tr>
<td rowspan="2" align="center" valign="top" width="25"><img alt="[Warning]" src="../../../../../../doc/src/images/warning.png"></td>
<th align="left">Warning</th>
</tr>
<tr><td align="left" valign="top"><p>
          To get all the functionalities of <code class="computeroutput"><span class="identifier">BOOST_TEST</span></code>
          family of assertions, a C++11 capable compiler is required, especially
          supporting the <code class="computeroutput"><span class="keyword">auto</span></code> and <code class="computeroutput"><span class="keyword">decltype</span></code> keywords and the variadic macros.
          The documentation focuses on these set of compilers. For compilers not
          supporting all the features of <code class="computeroutput"><span class="identifier">BOOST_TEST</span></code>,
          the macro <code class="computeroutput"><span class="identifier">BOOST_TEST_MACRO_LIMITED_SUPPORT</span></code>.
        </p></td></tr>
</table></div>
<a name="boost_test_statement_overloads"></a><h4>
<a name="boost_test.testing_tools.boost_test_universal_macro.h1"></a>
        <span class="phrase"><a name="boost_test.testing_tools.boost_test_universal_macro.complex_statements"></a></span><a class="link" href="boost_test_universal_macro.html#boost_test.testing_tools.boost_test_universal_macro.complex_statements">Complex
        statements</a>
      </h4>
<p>
        <code class="computeroutput"><span class="identifier">BOOST_TEST</span></code> provides an enhanced
        reporting capability: additional details of the failing operands and operations
        are provided in the log, as shown on the example below:
      </p>
<h6>
<a name="boost_test.testing_tools.boost_test_universal_macro.h2"></a>
        <span class="phrase"><a name="boost_test.testing_tools.boost_test_universal_macro.example_descr0"></a></span><a class="link" href="boost_test_universal_macro.html#boost_test.testing_tools.boost_test_universal_macro.example_descr0">Example:
        BOOST_TEST enhanced reporting</a>
      </h6>
<div class="informaltable"><table class="table">
<colgroup><col></colgroup>
<thead><tr><th>
                <p>
                  Code
                </p>
              </th></tr></thead>
<tbody><tr><td>
<pre xmlns:rev="http://www.cs.rpi.edu/~gregod/boost/tools/doc/revision" class="table-programlisting"><span class="preprocessor">#define</span> <span class="identifier">BOOST_TEST_MODULE</span> <span class="identifier">boost_test_macro3</span>
<span class="preprocessor">#include</span> <span class="special">&lt;</span><span class="identifier">boost</span><span class="special">/</span><span class="identifier">test</span><span class="special">/</span><span class="identifier">included</span><span class="special">/</span><span class="identifier">unit_test</span><span class="special">.</span><span class="identifier">hpp</span><span class="special">&gt;</span>

<span class="identifier">BOOST_AUTO_TEST_CASE</span><span class="special">(</span> <span class="identifier">test_op_reportings</span> <span class="special">)</span>
<span class="special">{</span>
  <span class="keyword">int</span> <span class="identifier">a</span> <span class="special">=</span> <span class="number">13</span><span class="special">,</span> <span class="identifier">b</span> <span class="special">=</span> <span class="number">12</span><span class="special">;</span>
  <span class="identifier">BOOST_TEST</span><span class="special">(</span><span class="identifier">a</span> <span class="special">==</span> <span class="identifier">b</span><span class="special">);</span>
  <span class="identifier">BOOST_TEST</span><span class="special">(</span><span class="identifier">a</span> <span class="special">&lt;</span> <span class="identifier">b</span><span class="special">);</span>
  <span class="identifier">BOOST_TEST</span><span class="special">(</span><span class="identifier">a</span> <span class="special">-</span> <span class="number">1</span> <span class="special">&lt;</span> <span class="identifier">b</span><span class="special">);</span>
  <span class="identifier">BOOST_TEST</span><span class="special">(</span><span class="identifier">b</span> <span class="special">&gt;</span> <span class="identifier">a</span> <span class="special">-</span> <span class="number">1</span><span class="special">);</span>
<span class="special">}</span>
</pre>
              </td></tr></tbody>
</table></div>
<div class="informaltable"><table class="table">
<colgroup><col></colgroup>
<thead><tr><th>
                <p>
                  Output
                </p>
              </th></tr></thead>
<tbody><tr><td>
<pre xmlns:rev="http://www.cs.rpi.edu/~gregod/boost/tools/doc/revision" class="table-programlisting"><span class="special">&gt;</span> <span class="special">./</span><span class="identifier">boost_test_macro3</span> <span class="special">--</span><span class="identifier">log_level</span><span class="special">=</span><span class="identifier">all</span>
<span class="identifier">Running</span> <span class="number">1</span> <span class="identifier">test</span> <span class="keyword">case</span><span class="special">...</span>
<span class="identifier">Entering</span> <span class="identifier">test</span> <span class="identifier">module</span> <span class="string">"boost_test_macro3"</span>
<span class="identifier">test</span><span class="special">.</span><span class="identifier">cpp</span><span class="special">(</span><span class="number">12</span><span class="special">):</span> <span class="identifier">Entering</span> <span class="identifier">test</span> <span class="keyword">case</span> <span class="string">"test_op_reportings"</span>
<span class="identifier">test</span><span class="special">.</span><span class="identifier">cpp</span><span class="special">(</span><span class="number">15</span><span class="special">):</span> <span class="identifier">error</span><span class="special">:</span> <span class="identifier">in</span> <span class="string">"test_op_reportings"</span><span class="special">:</span> <span class="identifier">check</span> <span class="identifier">a</span> <span class="special">==</span> <span class="identifier">b</span> <span class="identifier">has</span> <span class="identifier">failed</span> <span class="special">[</span><span class="number">13</span> <span class="special">!=</span> <span class="number">12</span><span class="special">]</span>
<span class="identifier">test</span><span class="special">.</span><span class="identifier">cpp</span><span class="special">(</span><span class="number">16</span><span class="special">):</span> <span class="identifier">error</span><span class="special">:</span> <span class="identifier">in</span> <span class="string">"test_op_reportings"</span><span class="special">:</span> <span class="identifier">check</span> <span class="identifier">a</span> <span class="special">&lt;</span> <span class="identifier">b</span> <span class="identifier">has</span> <span class="identifier">failed</span> <span class="special">[</span><span class="number">13</span> <span class="special">&gt;=</span> <span class="number">12</span><span class="special">]</span>
<span class="identifier">test</span><span class="special">.</span><span class="identifier">cpp</span><span class="special">(</span><span class="number">17</span><span class="special">):</span> <span class="identifier">error</span><span class="special">:</span> <span class="identifier">in</span> <span class="string">"test_op_reportings"</span><span class="special">:</span> <span class="identifier">check</span> <span class="identifier">a</span> <span class="special">-</span> <span class="number">1</span> <span class="special">&lt;</span> <span class="identifier">b</span> <span class="identifier">has</span> <span class="identifier">failed</span> <span class="special">[</span><span class="number">13</span> <span class="special">-</span> <span class="number">1</span> <span class="special">&gt;=</span> <span class="number">12</span><span class="special">]</span>
<span class="identifier">test</span><span class="special">.</span><span class="identifier">cpp</span><span class="special">(</span><span class="number">18</span><span class="special">):</span> <span class="identifier">error</span><span class="special">:</span> <span class="identifier">in</span> <span class="string">"test_op_reportings"</span><span class="special">:</span> <span class="identifier">check</span> <span class="identifier">b</span> <span class="special">&gt;</span> <span class="identifier">a</span> <span class="special">-</span> <span class="number">1</span> <span class="identifier">has</span> <span class="identifier">failed</span> <span class="special">[</span><span class="number">12</span> <span class="special">&lt;=</span> <span class="number">12</span><span class="special">]</span>
<span class="identifier">test</span><span class="special">.</span><span class="identifier">cpp</span><span class="special">(</span><span class="number">12</span><span class="special">):</span> <span class="identifier">Leaving</span> <span class="identifier">test</span> <span class="keyword">case</span> <span class="string">"test_op_reportings"</span><span class="special">;</span> <span class="identifier">testing</span> <span class="identifier">time</span><span class="special">:</span> <span class="number">484u</span><span class="identifier">s</span>
<span class="identifier">Leaving</span> <span class="identifier">test</span> <span class="identifier">module</span> <span class="string">"boost_test_macro3"</span><span class="special">;</span> <span class="identifier">testing</span> <span class="identifier">time</span><span class="special">:</span> <span class="number">588u</span><span class="identifier">s</span>

<span class="special">***</span> <span class="number">2</span> <span class="identifier">failures</span> <span class="identifier">are</span> <span class="identifier">detected</span> <span class="identifier">in</span> <span class="identifier">the</span> <span class="identifier">test</span> <span class="identifier">module</span> <span class="string">"boost_test_macro3"</span>
</pre>
              </td></tr></tbody>
</table></div>
<p>
        <code class="computeroutput"><span class="identifier">BOOST_TEST</span></code> parses the <code class="computeroutput"><span class="identifier">statement</span></code> and constructs an expression
        out of it. <code class="computeroutput"><span class="identifier">statement</span></code> may
        be a complex expressions containing almost any of the overloadable operators
        in C++:
      </p>
<div class="informaltable"><table class="table">
<colgroup>
<col>
<col>
</colgroup>
<thead><tr>
<th>
                <p>
                  Class of operation
                </p>
              </th>
<th>
                <p>
                  operators
                </p>
              </th>
</tr></thead>
<tbody>
<tr>
<td>
                <p>
                  binary comparisons
                </p>
              </td>
<td>
                <p>
                  <code class="computeroutput"><span class="special">==</span></code>, <code class="computeroutput"><span class="special">!=</span></code>, <code class="computeroutput"><span class="special">&lt;</span></code>,
                  <code class="computeroutput"><span class="special">&gt;</span></code>, <code class="computeroutput"><span class="special">&lt;=</span></code>, <code class="computeroutput"><span class="special">&gt;=</span></code>
                </p>
              </td>
</tr>
<tr>
<td>
                <p>
                  arithmetic compositions
                </p>
              </td>
<td>
                <p>
                  <code class="computeroutput"><span class="special">+</span></code>, <code class="computeroutput"><span class="special">-</span></code>,
                  <code class="computeroutput"><span class="special">*</span></code>, <code class="computeroutput"><span class="special">/</span></code>,
                  <code class="computeroutput"><span class="special">%</span></code>
                </p>
              </td>
</tr>
<tr>
<td>
                <p>
                  bitwise compositions
                </p>
              </td>
<td>
                <p>
                  <code class="computeroutput"><span class="special">|</span></code>, <code class="computeroutput"><span class="special">&amp;</span></code>,
                  <code class="computeroutput"><span class="special">^</span></code>, <code class="computeroutput"><span class="special">&lt;&lt;</span></code>,
                  <code class="computeroutput"><span class="special">&gt;&gt;</span></code>
                </p>
              </td>
</tr>
<tr>
<td>
                <p>
                  assignments
                </p>
              </td>
<td>
                <p>
                  <code class="computeroutput"><span class="special">=</span></code>, <code class="computeroutput"><span class="special">+=</span></code>,
                  <code class="computeroutput"><span class="special">-=</span></code>, <code class="computeroutput"><span class="special">*=</span></code>, <code class="computeroutput"><span class="special">/=</span></code>,
                  <code class="computeroutput"><span class="special">%=</span></code>, <code class="computeroutput"><span class="special">&lt;&lt;=</span></code>, <code class="computeroutput"><span class="special">&gt;&gt;=</span></code>,
                  <code class="computeroutput"><span class="special">&amp;=</span></code>, <code class="computeroutput"><span class="special">^=</span></code>, <code class="computeroutput"><span class="special">|=</span></code>
                </p>
              </td>
</tr>
</tbody>
</table></div>
<p>
        <code class="computeroutput"><span class="identifier">statement</span></code> is evaluated and
        cast to <code class="computeroutput"><span class="keyword">bool</span></code>, as if it would
        appear as argument to an <code class="computeroutput"><span class="keyword">if</span></code>
        statement: this is the result of the assertion
      </p>
<h4>
<a name="boost_test.testing_tools.boost_test_universal_macro.h3"></a>
        <span class="phrase"><a name="boost_test.testing_tools.boost_test_universal_macro.uniform_reporting"></a></span><a class="link" href="boost_test_universal_macro.html#boost_test.testing_tools.boost_test_universal_macro.uniform_reporting">Uniform
        reporting</a>
      </h4>
<p>
        This tool is provided in three variants corresponding to the corresponding
        <a class="link" href="tools_assertion_severity_level.html" title="Assertion severity level">severity
        levels</a>. These three levels of assertions are reported into the test
        log and output, as described in details in the section. The granularity of
        the report depends on the current <a class="link" href="../utf_reference/rt_param_reference/log_level.html" title="log_level">log
        level</a> and <a class="link" href="../utf_reference/rt_param_reference/report_level.html" title="report_level">report
        level</a>.
      </p>
<a name="boost_test_statement_limitations"></a><h4>
<a name="boost_test.testing_tools.boost_test_universal_macro.h4"></a>
        <span class="phrase"><a name="boost_test.testing_tools.boost_test_universal_macro.limitations_workaround"></a></span><a class="link" href="boost_test_universal_macro.html#boost_test.testing_tools.boost_test_universal_macro.limitations_workaround">Limitations
        &amp; workaround</a>
      </h4>
<p>
        There are a few constructions that are however unsupported, but adding an
        extra bracket usually solves that:
      </p>
<div class="itemizedlist"><ul class="itemizedlist" style="list-style-type: disc; ">
<li class="listitem">
            statements containing ternary conditions: those statement should be surrounded
            by parenthesis as they cannot be overloaded
          </li>
<li class="listitem">
            statements containing commas: those statements will be intercepted by
            the preprocessor
          </li>
<li class="listitem">
<p class="simpara">
            compound statements containing any logical composition <code class="computeroutput"><span class="special">||</span></code>, <code class="computeroutput"><span class="special">&amp;&amp;</span></code>.
            Those are disabled intentionally and should be surrounded by parenthesis
          </p>
<pre class="programlisting"><span class="identifier">BOOST_TEST</span><span class="special">((</span><span class="keyword">true</span> <span class="special">||</span> <span class="keyword">false</span><span class="special">));</span>
</pre>
<p class="simpara">
            The full details are given in <a class="link" href="internal_details.html" title="BOOST_TEST: details on expressions">this
            section</a>.
          </p>
</li>
</ul></div>
<h6>
<a name="boost_test.testing_tools.boost_test_universal_macro.h5"></a>
        <span class="phrase"><a name="boost_test.testing_tools.boost_test_universal_macro.example_descr1"></a></span><a class="link" href="boost_test_universal_macro.html#boost_test.testing_tools.boost_test_universal_macro.example_descr1">Example:
        BOOST_TEST limitation and workaround</a>
      </h6>
<div class="informaltable"><table class="table">
<colgroup><col></colgroup>
<thead><tr><th>
                <p>
                  Code
                </p>
              </th></tr></thead>
<tbody><tr><td>
<pre xmlns:rev="http://www.cs.rpi.edu/~gregod/boost/tools/doc/revision" class="table-programlisting"><span class="preprocessor">#define</span> <span class="identifier">BOOST_TEST_MODULE</span> <span class="identifier">boost_test_macro_workaround</span>
<span class="preprocessor">#include</span> <span class="special">&lt;</span><span class="identifier">boost</span><span class="special">/</span><span class="identifier">test</span><span class="special">/</span><span class="identifier">included</span><span class="special">/</span><span class="identifier">unit_test</span><span class="special">.</span><span class="identifier">hpp</span><span class="special">&gt;</span>
<span class="preprocessor">#include</span> <span class="special">&lt;</span><span class="identifier">sstream</span><span class="special">&gt;</span>

<span class="identifier">BOOST_AUTO_TEST_CASE</span><span class="special">(</span> <span class="identifier">test_logical_not_allowed</span> <span class="special">)</span>
<span class="special">{</span>
  <span class="comment">// Boost Unit Test Framework prevents compilation of</span>
  <span class="comment">// BOOST_TEST(true &amp;&amp; true);</span>
  <span class="identifier">BOOST_TEST</span><span class="special">((</span><span class="keyword">true</span> <span class="special">&amp;&amp;</span> <span class="keyword">true</span><span class="special">));</span> <span class="comment">// with extra brackets, it works as expected</span>
<span class="special">}</span>

<span class="identifier">BOOST_AUTO_TEST_CASE</span><span class="special">(</span> <span class="identifier">test_ternary</span> <span class="special">)</span>
<span class="special">{</span>
  <span class="keyword">int</span> <span class="identifier">a</span> <span class="special">=</span> <span class="number">1</span><span class="special">;</span>
  <span class="keyword">int</span> <span class="identifier">b</span> <span class="special">=</span> <span class="number">2</span><span class="special">;</span>
  <span class="comment">// Boost Unit Test Framework prevents compilation of</span>
  <span class="comment">// BOOST_TEST(a == b ? true : false);</span>
  <span class="identifier">BOOST_TEST</span><span class="special">((</span><span class="identifier">a</span> <span class="special">+</span> <span class="number">1</span> <span class="special">==</span> <span class="identifier">b</span> <span class="special">?</span> <span class="keyword">true</span> <span class="special">:</span> <span class="keyword">false</span><span class="special">));</span> <span class="comment">// again works as expected with extra brackets</span>
<span class="special">}</span>
</pre>
              </td></tr></tbody>
</table></div>
<div class="informaltable"><table class="table">
<colgroup><col></colgroup>
<thead><tr><th>
                <p>
                  Output
                </p>
              </th></tr></thead>
<tbody><tr><td>
<pre xmlns:rev="http://www.cs.rpi.edu/~gregod/boost/tools/doc/revision" class="table-programlisting"><span class="special">&gt;</span> <span class="special">./</span><span class="identifier">boost_test_macro_workaround</span> <span class="special">--</span><span class="identifier">log_level</span><span class="special">=</span><span class="identifier">all</span>
<span class="identifier">Running</span> <span class="number">2</span> <span class="identifier">test</span> <span class="identifier">cases</span><span class="special">...</span>
<span class="identifier">Entering</span> <span class="identifier">test</span> <span class="identifier">module</span> <span class="string">"boost_test_macro_workaround"</span>
<span class="identifier">test</span><span class="special">.</span><span class="identifier">cpp</span><span class="special">:</span><span class="number">13</span><span class="special">:</span> <span class="identifier">Entering</span> <span class="identifier">test</span> <span class="keyword">case</span> <span class="string">"test_logical_not_allowed"</span>
<span class="identifier">test</span><span class="special">.</span><span class="identifier">cpp</span><span class="special">:</span><span class="number">17</span><span class="special">:</span> <span class="identifier">info</span><span class="special">:</span> <span class="identifier">check</span> <span class="special">(</span><span class="keyword">true</span> <span class="special">&amp;&amp;</span> <span class="keyword">true</span><span class="special">)</span> <span class="identifier">has</span> <span class="identifier">passed</span>
<span class="identifier">test</span><span class="special">.</span><span class="identifier">cpp</span><span class="special">:</span><span class="number">13</span><span class="special">:</span> <span class="identifier">Leaving</span> <span class="identifier">test</span> <span class="keyword">case</span> <span class="string">"test_logical_not_allowed"</span><span class="special">;</span> <span class="identifier">testing</span> <span class="identifier">time</span><span class="special">:</span> <span class="number">183u</span><span class="identifier">s</span>
<span class="identifier">test</span><span class="special">.</span><span class="identifier">cpp</span><span class="special">:</span><span class="number">20</span><span class="special">:</span> <span class="identifier">Entering</span> <span class="identifier">test</span> <span class="keyword">case</span> <span class="string">"test_ternary"</span>
<span class="identifier">test</span><span class="special">.</span><span class="identifier">cpp</span><span class="special">:</span><span class="number">26</span><span class="special">:</span> <span class="identifier">info</span><span class="special">:</span> <span class="identifier">check</span> <span class="special">(</span><span class="identifier">a</span> <span class="special">+</span> <span class="number">1</span> <span class="special">==</span> <span class="identifier">b</span> <span class="special">?</span> <span class="keyword">true</span> <span class="special">:</span> <span class="keyword">false</span><span class="special">)</span> <span class="identifier">has</span> <span class="identifier">passed</span>
<span class="identifier">test</span><span class="special">.</span><span class="identifier">cpp</span><span class="special">:</span><span class="number">20</span><span class="special">:</span> <span class="identifier">Leaving</span> <span class="identifier">test</span> <span class="keyword">case</span> <span class="string">"test_ternary"</span><span class="special">;</span> <span class="identifier">testing</span> <span class="identifier">time</span><span class="special">:</span> <span class="number">123u</span><span class="identifier">s</span>
<span class="identifier">Leaving</span> <span class="identifier">test</span> <span class="identifier">module</span> <span class="string">"boost_test_macro_workaround"</span><span class="special">;</span> <span class="identifier">testing</span> <span class="identifier">time</span><span class="special">:</span> <span class="number">547u</span><span class="identifier">s</span>

<span class="special">***</span> <span class="identifier">No</span> <span class="identifier">errors</span> <span class="identifier">detected</span>
</pre>
              </td></tr></tbody>
</table></div>
</div>
<table xmlns:rev="http://www.cs.rpi.edu/~gregod/boost/tools/doc/revision" width="100%"><tr>
<td align="left"></td>
<td align="right"><div class="copyright-footer">Copyright © 2001-2020 Boost.Test contributors<p>
        Distributed under the Boost Software License, Version 1.0. (See accompanying
        file LICENSE_1_0.txt or copy at <a href="http://www.boost.org/LICENSE_1_0.txt" target="_top">http://www.boost.org/LICENSE_1_0.txt</a>)
      </p>
</div></td>
</tr></table>
<hr>
<div class="spirit-nav">
<a accesskey="p" href="tools_assertion_severity_level.html"><img src="../../../../../../doc/src/images/prev.png" alt="Prev"></a><a accesskey="u" href="../testing_tools.html"><img src="../../../../../../doc/src/images/up.png" alt="Up"></a><a accesskey="h" href="../../index.html"><img src="../../../../../../doc/src/images/home.png" alt="Home"></a><a accesskey="n" href="reports.html"><img src="../../../../../../doc/src/images/next.png" alt="Next"></a>
</div>
</body>
</html>
